package com.example.service.impl;

import com.example.entity.LiuyanMessage;
import com.example.entity.LiuyanMessageDTO;
import com.example.mapper.LiuYanMapper;
import com.example.service.LiuYanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

@Service
public class LiuYanServiceImpl implements LiuYanService {

    @Resource
    private LiuYanMapper liuYanMapper;




    /**新增
     *
     */
    @Override
    public void add(LiuyanMessageDTO liuyanMessageDTO) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        LiuyanMessage liuyanMessage = LiuyanMessage.builder()
                .text(liuyanMessageDTO.getText())
                .authorId(liuyanMessageDTO.getUserId())
                .authorName(liuyanMessageDTO.getUserName())
                .createTime(timestamp)
                .build();
        liuYanMapper.insert(liuyanMessage);
    }

    @Override
    public void deleteById(Integer id) {
        liuYanMapper.deleteById(id);
    }

    @Override
    public PageInfo<LiuyanMessage> selectPage(Integer pageNum, Integer pageSize, Integer authorId, String authorName, String userRole) {
        PageHelper.startPage(pageNum,pageSize);
        List<LiuyanMessage> userList= liuYanMapper.selectAll(authorId,authorName);
        return PageInfo.of(userList);
    }

}
